import java.util.Scanner;

public class test2 {
    //蓝桥 能量晶石
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        long min = Long.MAX_VALUE;
        long count = 0L;
        int[] arr = new int[n];
        for(int i = 0 ;i < n;i++){
            arr[i] = scan.nextInt();
            min = min<arr[i]?min:arr[i];
        }

        for(int i = 0 ;i < n;i++){
            count = count + (arr[i] - min);
        }
        System.out.println(count);

        scan.close();
    }
}
